home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_5.lha
/
5_5
/
5_5a5.c
< prev
next >
Wrap
Text File
|
1993-08-08
|
1KB
|
58 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
tatic tree* prim(istream& input)
tree* ret = new tree;
switch (curr_tok.type)
{
case NUMBER:
f (debug) cout << "prim() sees NUMBER " << curr_tok.value << "\n"; // DELETE
ret->type = NUMBER;
ret->value = curr_tok.value;
get_token(input); // skip number
f (debug) { cout << "prim():ret:\n"; ret->print(0); } // DELETE
return ret;
case MINUS:
f (debug) cout << "prim() sees -\n"; // DELETE
ret->type = MINUS;
get_token(input); // skip '-'
ret->left = prim(input);
ret->right = 0;
f (debug) { cout << "prim():ret:\n"; ret->print(0); } // DELETE
return ret;
case LP:
f (debug) cout << "prim() sees (\n"; // DELETE
ret->type = LP;
get_token(input); // skip '('
ret->left = get_expr(input);
if (curr_tok.type != RP)
{
error(") expected");
break;
}
get_token(input); // skip ')'
f (debug) { cout << "prim():ret:\n"; ret->print(0); } // DELETE
return ret;
case END:
f (debug) cout << "prim() sees END\n"; // DELETE
error("end of expression unexpected");
break;
default:
f (debug) cout << "prim() sees UNKNOWN\n"; // DELETE
error("unknown type within tree");
break;
}
// error case
ret->value = 0;
ret->type = NUMBER;
return ret;